package me.moscrop.RootCommand.commands;

import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class PlayerControl{
	
	//Start heal based methods.
	
	public static boolean healSender(CommandSender sender, String[] args)
	{
		Player personToHeal;
		
		//if there is arguments
		if(args.length > 0 && (args[0].contentEquals("") == false))
		{
			//get the user and heal them
			personToHeal = sender.getServer().getPlayer(args[0]);
			//if player exists heal them
			if(personToHeal != null)
			{
				personToHeal.sendMessage(ChatColor.GREEN + personToHeal.getDisplayName() + " now has a full health.");
				personToHeal.sendMessage(ChatColor.GREEN + "You now have a full health.");
				personToHeal.setHealth(20);; // heal and verbose
			}else{
				((Player) sender).sendMessage(ChatColor.RED + args[0] + " doesnt exist.");
				return true;
			}
		}
		
		//From this point on theres no args so the player wants to feel them self
		
		if((sender instanceof Player) == false)
		{
			sender.sendMessage("This isnt a command for the console silly.");
			return false;
		}
		
		if(args.length == 0)
		{
			personToHeal = (Player) sender;
			personToHeal.sendMessage(ChatColor.GREEN + "You now have full health.");
			personToHeal.setHealth(20); //heal and verbose
		}
		
		return true;
	}
	
	
	
	//End heal based methods.
	
	//Start feed based methods.
	public static boolean feedSender(CommandSender sender, String[] args)
	{
	Player personToFeed;
	
	//if there is arguments
	if(args.length > 0 && (args[0].contentEquals("") == false))
	{
		//get the user and heal them
		personToFeed = sender.getServer().getPlayer(args[0]);
		//if player exists heal them
		if(personToFeed != null)
		{
			((Player) sender).sendMessage(ChatColor.GREEN + personToFeed.getDisplayName() +" now has a full tummy.");
			personToFeed.sendMessage(ChatColor.GREEN + "You now have a full tummy.");
			personToFeed.setFoodLevel(20); // heal and verbose
			return true;
		}else{
			((Player) sender).sendMessage(ChatColor.RED + args[0] + " doesnt exist.");
			return true;
		}
	}
	
	//From this point on theres no args so the player wants to feel them self
	
	if((sender instanceof Player) == false)
	{
		sender.sendMessage("This isnt a command for the console silly.");
		return false;
	}
	
	if(args.length == 0)
	{
		personToFeed = (Player) sender;
		personToFeed.sendMessage(ChatColor.GREEN + "You now have a full tummy.");;
		personToFeed.setFoodLevel(20);
		//heal and verbose
	}
	
	return true;
}


	
	//End feed based methods.
	
	//Start toggle based methods.
	
		public static boolean toggleSender(CommandSender sender, String[] args)
		{
			Player personToToggle;
			
			//if there is arguments
			if(args.length > 0 && (args[0].contentEquals("") == false))
			{
				//get the user and heal them
				personToToggle = sender.getServer().getPlayer(args[0]);
				//if player exists heal them
				if(personToToggle != null)
				{
					
					toggle(personToToggle); // heal and verbose
					((Player) sender).sendMessage(ChatColor.GREEN + personToToggle.getDisplayName() + " is now in game mode " + personToToggle.getGameMode().toString() );
					personToToggle.sendMessage(ChatColor.GREEN + "You are now in game mode " + personToToggle.getGameMode().toString() );
					toggle(personToToggle);
					return true;
				}else{
					((Player) sender).sendMessage(ChatColor.RED + args[0] + " doesnt exist.");
					return false;
				}
			}
			
			//From this point on theres no args so the player wants to feel them self
			
			if((sender instanceof Player) == false)
			{
				sender.sendMessage("This isnt a command for the console silly.");
				return false;
			}
			
			if(args.length == 0)
			{
				personToToggle = (Player) sender;
				toggle(personToToggle); //heal and verbose
				personToToggle.sendMessage(ChatColor.GREEN + "You are now in game mode " + personToToggle.getGameMode().toString() );
			}
			
			return true;
		}
		

		public static void toggle(Player player)
		{
			if(player.getGameMode() == GameMode.CREATIVE)
			{
				player.setGameMode(GameMode.SURVIVAL);
			}else{
				player.setGameMode(GameMode.CREATIVE);
			}
		}
		
		//End toggle based methods.
	
}
